*****************************************************************************************
*Table B.4s
*This table reports a robustness check to Panel B of Table 3 by measuring value as the amount a household is willingness to accept in lieu of ration
*****************************************************************************************

use "${SurveyDataDir}/JH_ePOS_HH_DataforAnalysis.dta",clear

*******************************************************************************
keep if ss_code == "SS01"

*******************************************************************************
svyset [pw = pweight]


count if ghost_final == 1
scalar ghosts = r(N)
scalar obs = 3960   

*Get relative weights of AAY and PH rationcard holders by whether RC is in an urban area
sum pweight if rationcardtype == "AAY" & isurban == 0
scalar AAY_weight0 = r(sum)

sum pweight if rationcardtype == "PH" & isurban == 0
scalar PH_weight0 = r(sum)

sum pweight if rationcardtype == "AAY" & isurban == 1
scalar AAY_weight1 = r(sum)

sum pweight if rationcardtype == "PH" & isurban == 1
scalar PH_weight1 = r(sum)


label var c6_WTA_mar17 "March WTA"
label var c6_WTA_feb17 "February WTA"
label var c6_WTA_jan17 "January WTA"

svyset [pw = pweight]

count
scalar obs = 3960 

qui svy: mean c6_WTA_mar17 if treatment == 0
qui estat sd
matrix Mean0 = r(mean)
eststo mar: xi: reg c6_WTA_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

qui svy: mean c6_WTA_feb17 if treatment == 0
qui estat sd
matrix Mean0 = r(mean)
eststo feb: xi: reg c6_WTA_feb17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

qui svy: mean c6_WTA_jan17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)

eststo jan: xi: reg c6_WTA_jan17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

preserve
keep uid c6_WTA_mar17 c6_WTA_feb17 c6_WTA_jan17 treatment strata pweight block_code
gen c6_WTA3 = c6_WTA_mar17
gen c6_WTA2 = c6_WTA_feb17
gen c6_WTA1 = c6_WTA_jan17
drop c6_WTA_mar17 c6_WTA_feb17 c6_WTA_jan17
reshape long c6_WTA, i(uid) j(month)

gen treatmentXmonth=treatment*month

count
scalar obs_all = 3*(3960 - ghosts)


qui svy: mean c6_WTA if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo pool1: xi: reg c6_WTA treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs_all

qui svy: mean c6_WTA if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo pool2: xi: reg c6_WTA treatment i.strata month treatmentXmonth [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs_all



restore





label var c6_WTA_mar17 "March WTA"
label var c6_WTA_feb17 "February WTA"
label var c6_WTA_jan17 "January WTA"

*Recode missing values as zero if HH did non recieve ration in a given month

replace c6_WTA_mar17 = 0 if c6a_no_ration_flag_mar17 == 1
replace c6_WTA_feb17 = 0 if c6a_no_ration_flag_feb17 == 1
replace c6_WTA_jan17 = 0 if c6a_no_ration_flag_jan17 == 1

count
scalar obs = 3960 - ghosts

svyset [pw = pweight]

qui svy: mean c6_WTA_mar17 if treatment == 0
qui estat sd
matrix Mean0 = r(mean)
eststo mar_2: xi: reg c6_WTA_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

qui svy: mean c6_WTA_feb17 if treatment == 0
qui estat sd
matrix Mean0 = r(mean)
eststo feb_2: xi: reg c6_WTA_feb17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

qui svy: mean c6_WTA_jan17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)

eststo jan_2: xi: reg c6_WTA_jan17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

preserve
keep uid c6_WTA_mar17 c6_WTA_feb17 c6_WTA_jan17 treatment strata pweight block_code
gen c6_WTA3 = c6_WTA_mar17
gen c6_WTA2 = c6_WTA_feb17
gen c6_WTA1 = c6_WTA_jan17
drop c6_WTA_mar17 c6_WTA_feb17 c6_WTA_jan17
reshape long c6_WTA, i(uid) j(month)


count
scalar obs_all = 3*(3960 - ghosts)

gen treatmentXmonth=treatment*month

qui svy: mean c6_WTA if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo pool1_2: xi: reg c6_WTA treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs_all

qui svy: mean c6_WTA if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo pool2_2: xi: reg c6_WTA treatment i.strata month treatmentXmonth [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs_all

restore

loc tabname "${OutputDir}/TableB_4.tex" 
cd "${adoDir}"
loc nc 5				
MultiPartTabStart, ///
			ncol(`nc') tabname(`tabname') ///
			mgroups("January" "February" "March" "Pooled") ///
			pattern(1 1 1 1 0) width("\hsize")	
				
				
MultiPartTabPanelStart, ///
			ncol(`nc') tabname(`tabname') ///
			panelstring("Panel A: All households")
			
MultiPartTabPanelEnd, ///
			ncol(`nc') tabname(`tabname') ///
			models("jan_2 feb_2 mar_2 pool1_2 pool2_2") ///
			drop(_cons _Istrata*) varlabels(treatment "Treatment" month "Month" treatmentXmonth "Treatment X Month"  ///
			, elist(treatment \addlinespace month \addlinespace treatmentXmonth \addlinespace) ) ///
			cells(b(star fmt(%12.2g) ) se(par(( )) fmt(%12.2g) )  ) ///
			starlevels( * 0.10 ** 0.05 *** 0.01) ///
			stats(control_mean N, label("Control mean" "Observations") fmt(%12.2gc %12.2gc))

MultiPartTabPanelStart, ///
			ncol(`nc') tabname(`tabname') ///
			panelstring("Panel B: Excludes HHs who did not purchase ration in a given month")
			
MultiPartTabPanelEnd, ///
			ncol(`nc') tabname(`tabname') ///
			models("jan feb mar pool1 pool2") ///
			drop(_cons _Istrata*) varlabels(treatment "Treatment" month "Month" treatmentXmonth "Treatment X Month"  ///
			, elist(treatment \addlinespace month \addlinespace treatmentXmonth \addlinespace) ) ///
			cells(b(star fmt(%12.2g) ) se(par(( )) fmt(%12.2g) )  ) ///
			starlevels( * 0.10 ** 0.05 *** 0.01) ///
			stats(control_mean N, label("Control mean" "Observations") fmt(%12.2gc %12.2gc))

MultiPartTabEnd, ///
			ncol(`nc') tabname(`tabname')
		